using System;
using System.Collections.Generic;
using System.Text;
using ElteIk.RoboSoccer.Core;
using ElteIk.RoboSoccer.Communication;

namespace ElteIk.RoboSoccer.TesterTactics
{
	/// <summary>
	/// Brute force tactics which means - rush towards the ball at max power, no matter where you are (dont care about owngoals)
	/// </summary>
	public class BruteForceTactics : ITactics
    {
        #region Private fields

        protected RoboSoccerGame game;
        protected RoboSoccerTeam team;

        protected SimpleController[] robotControllers;

        protected int teamId;

        #endregion

        #region Lifecycle

        public BruteForceTactics(int teamId)
        {
            this.teamId = teamId;
        }

        public void InitializeTactics(RoboSoccerGame game, int teamId)
        {
            this.game = game;

            if (teamId == 1)
                this.team = game.LeftTeam;
            else if (teamId == 2)
                this.team = game.RightTeam;

            robotControllers = new SimpleController[team.Players.Count];
            for (int i = 0; i < team.Players.Count; ++i)
            {
                robotControllers[i] = new SimpleController(team.Robots[i], game.Field);
            }
        }

        //public BruteForceTactics(RoboSoccerGame game, int teamId)
        //{
        //    InitializeTactics(game, teamId);
        //}

        #endregion

        #region Public properties

        public RoboSoccerGame Game
        {
            get { return game; }
            set 
            { 
                game = value;
                InitializeTactics(game, teamId);
            }
        }

        #endregion

        #region Tactics

        public void Do()
		{
            if (game == null)
                return;

			foreach (SimpleController controller in robotControllers)
            {
                controller.MoveTo(game.Ball.Position);
            }
        }

        #endregion
    }
}
